<?
if(isset($_POST['Submit']))
{
	if(isset($_POST['newpass']) && $_POST['newpass'] != "")
	{
		if(isset($_POST['newpass']))
		{
		$newpass=md5($_POST['newpass']);
		}
		//$userid=$_POST['userid'];
		
		$sqlcon="SELECT * FROM siteadmin WHERE pswd='".md5($_POST['oldpass'])."'";	
		$resultcon= mysql_query($sqlcon) or die(mysql_error());
		if(mysql_num_rows($resultcon)<1)
		{ 
			$msg="Old Password is not correct";
		}
		if(mysql_num_rows($resultcon)>0)
		{
			 $target_path = "../images/";
			 $ts=time();
			 $products_picture = "";
			 if($_FILES['logo']['name'] != "")
			 {
				$qr_image="select logo from siteadmin where 1";
				$result_image=mysql_query($qr_image) or die($qr_image);
				$row_image=mysql_fetch_array($result_image);
				$img_path="../images/".$row_image["logo"];	
				if(is_file("$img_path"))
				{
				   unlink("$img_path"); 
				}
				$target_path = $target_path .$ts. basename($_FILES['logo']['name']);
				if(move_uploaded_file($_FILES['logo']['tmp_name'], $target_path)) 
				{ 
					$products_picture=$ts. basename( $_FILES['logo']['name']);
				}
				$SQL1 ="update `siteadmin` set `logo` = '".$products_picture."' where 1";
				$Result2 = mysql_query($SQL1) or die($SQL1);
			 }
			 
			 $target_path = "../images/";
			 $ts=time();
			 $products_picture = "";
			 if($_FILES['cms_logo']['name'] != "")
			 {
				$qr_image="select cms_logo from siteadmin where 1";
				$result_image=mysql_query($qr_image) or die($qr_image);
				$row_image=mysql_fetch_array($result_image);
				$img_path="../images/".$row_image["cms_logo"];	
				if(is_file("$img_path"))
				{
				   unlink("$img_path"); 
				}
				$target_path = $target_path .$ts. basename($_FILES['cms_logo']['name']);
				if(move_uploaded_file($_FILES['cms_logo']['tmp_name'], $target_path)) 
				{ 
					$products_picture=$ts. basename( $_FILES['cms_logo']['name']);
				}
				$SQL1 ="update `siteadmin` set `cms_logo` = '".$products_picture."' where 1";
				$Result2 = mysql_query($SQL1) or die($SQL1);
			 }
			$sql="UPDATE siteadmin set pswd='".$newpass."', pswd2='$_POST[newpass]', ip='".$_SERVER['REMOTE_ADDR']."', email='".$_REQUEST['email']."', company='".$_REQUEST['company']."', address='".$_REQUEST['address']."', city='".$_REQUEST['city']."', state='".$_REQUEST['state']."', zipcode='".$_REQUEST['zipcode']."', country='".$_REQUEST['country']."', google_map_key='".$_REQUEST['google_map_key']."'";
		
			$result= mysql_query($sql) or die(mysql_error());
			if($result)
			$msg="Update Complete!";  
		}
	}
	else
	{
			 $target_path = "../images/";
			 $ts=time();
			 $products_picture = "";
			 if($_FILES['logo']['name'] != "")
			 {
				$qr_image="select logo from siteadmin where 1";
				$result_image=mysql_query($qr_image) or die($qr_image);
				$row_image=mysql_fetch_array($result_image);
				$img_path="../images/".$row_image["logo"];	
				if(is_file("$img_path"))
				{
				   unlink("$img_path"); 
				}
				$target_path = $target_path .$ts. basename($_FILES['logo']['name']);
				if(move_uploaded_file($_FILES['logo']['tmp_name'], $target_path)) 
				{ 
					$products_picture=$ts. basename( $_FILES['logo']['name']);
				}
				$SQL1 ="update `siteadmin` set `logo` = '".$products_picture."' where 1";
				$Result2 = mysql_query($SQL1) or die($SQL1);
			 }
			 
			 $target_path = "../images/";
			 $ts=time();
			 $products_picture = "";
			 if($_FILES['cms_logo']['name'] != "")
			 {
				$qr_image="select cms_logo from siteadmin where 1";
				$result_image=mysql_query($qr_image) or die($qr_image);
				$row_image=mysql_fetch_array($result_image);
				$img_path="../images/".$row_image["cms_logo"];	
				if(is_file("$img_path"))
				{
				   unlink("$img_path"); 
				}
				$target_path = $target_path .$ts. basename($_FILES['cms_logo']['name']);
				if(move_uploaded_file($_FILES['cms_logo']['tmp_name'], $target_path)) 
				{ 
					$products_picture=$ts. basename( $_FILES['cms_logo']['name']);
				}
				$SQL1 ="update `siteadmin` set `cms_logo` = '".$products_picture."' where 1";
				$Result2 = mysql_query($SQL1) or die($SQL1);
			 }
			 
		$sql="UPDATE siteadmin set ip='".$_SERVER['REMOTE_ADDR']."', email='".$_REQUEST['email']."', company='".$_REQUEST['company']."', address='".$_REQUEST['address']."', city='".$_REQUEST['city']."', state='".$_REQUEST['state']."', zipcode='".$_REQUEST['zipcode']."', country='".$_REQUEST['country']."', google_map_key='".$_REQUEST['google_map_key']."'";
		
			$result= mysql_query($sql) or die(mysql_error());
			if($result)
			$msg="Update Complete!";
	}	
}
?>
<script language="javascript">
function checkblank()
{
	if(document.getElementById("oldpass").value=='')
	{
		alert("Please fill old password field");
		document.getElementById("oldpass").focus();
		return false;
	}
	/*else 
	if(document.getElementById("newpass").value=='')
	{
		alert("Please fill new password field");
		document.getElementById("newpass").focus();
		return false;
	}
	else if(document.getElementById("confirmpass").value=='')
	{
		alert("Please fill confirm password field");
		document.getElementById("confirmpass").focus();
		return false;
	}*/
	else if(document.getElementById("confirmpass").value!=document.getElementById("newpass").value)
	{
		alert("New password and confirm password should be same");
		document.getElementById("confirmpass").focus();
		return false;
	}
}
</script>
<?
	$s1 = "select * from siteadmin where 1";
	$q1 = mysql_query($s1) or die($s1);
	$r1 = mysql_fetch_array($q1);
?>
<form action="" method="post"  name="form1" id="form1" enctype="multipart/form-data">
  <table width="80%"  border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" align="center" class="smalltext">If you want to change the password, Then please enter the following information </td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" align="center" class="Redsmalltext"><?php echo $msg?></td>
    </tr>
	 <tr>
      <td width="31%" align="right" class="Main_heading3"><span class="smalltext">Email: </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><input name="email" type="text" class="txtField1" id="email" size="45" value="<?=$r1["email"]?>"> </td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
	<tr>
      <td width="31%" align="right" class="Main_heading3"><span class="smalltext">Company: </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><input name="company" type="text" class="txtField1" id="company" size="45" value="<?=$r1["company"]?>"> </td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
	<tr>
      <td width="31%" align="right" class="Main_heading3"><span class="smalltext">Addres : </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><input name="address" type="text" class="txtField1" id="address" size="45" value="<?=$r1["address"]?>"> </td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
	<tr>
      <td width="31%" align="right" class="Main_heading3"><span class="smalltext">City: </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><input name="city" type="text" class="txtField1" id="city" size="45" value="<?=$r1["city"]?>"> </td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
	<tr>
      <td width="31%" align="right" class="Main_heading3"><span class="smalltext">State: </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><input name="state" type="text" class="txtField1" id="state" size="45" value="<?=$r1["state"]?>"> </td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
	<tr>
      <td width="31%" align="right" class="Main_heading3"><span class="smalltext">Zipcode: </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><input name="zipcode" type="text" class="txtField1" id="zipcode" size="45" value="<?=$r1["zipcode"]?>"> </td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
	<tr>
      <td width="31%" align="right" class="Main_heading3"><span class="smalltext">Country: </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><input name="country" type="text" class="txtField1" id="country" size="45" value="<?=$r1["country"]?>"> </td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
	<tr>
      <td width="31%" align="right" class="Main_heading3"><span class="smalltext">Google Map Key: </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><input name="google_map_key" type="text" class="txtField1" id="google_map_key" size="45" value="<?=$r1["google_map_key"]?>"> </td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
	<tr>
      <td width="31%" align="right" class="Main_heading3" valign="bottom"><span class="smalltext">Logo: </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><? if(is_file("../images/".$r1["logo"]))
			{?><img src="<?=$path?>images/<?=$r1["logo"]?>"/><br /><? }?><input name="logo" type="file" class="txtField1" id="logo" size="45"> </td>
    </tr>
	 <!--<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
	<tr>
      <td width="31%" align="right" class="Main_heading3" valign="bottom"><span class="smalltext">CMS Logo: </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><? if(is_file("../images/".$r1["cms_logo"]))
			{?><img src="<?=$path?>images/<?=$r1["cms_logo"]?>"/><br /><? }?><input name="cms_logo" type="file" class="txtField1" id="cms_logo" size="45"> </td>
    </tr>-->
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
    <tr>
      <td width="31%" align="right" class="Main_heading3"><span class="smalltext">Old Password: </span></td>
      <td width="69%" align="left" class="EM_data_table_inputarea11"><input name="oldpass" type="password" class="txtField1" id="oldpass" size="45"  value="<?=$r1["pswd2"]?>">
      <font class="Redsmalltext">*</font> </td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="Main_heading3"><span class="smalltext">New Password: </span></td>
      <td align="left" class="EM_data_table_inputarea11"><input name="newpass" type="password" class="txtField1" id="newpass" size="45" maxlength="20">
          <font class="Redsmalltext">*(Max 20 characters) </font></td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="smalltext">Confirm Password: </td>
      <td align="left" class="EM_data_table_inputarea11"><input name="confirmpass" type="password" class="txtField1" id="confirmpass" size="45" maxlength="20">
          <font class="Redsmalltext">*(Max 20 characters)</font></td>
    </tr>
	<tr>
      <td colspan="2" align="center" class="Redsmalltext">&nbsp;</td>
    </tr>
    <tr>
      <td height="30">&nbsp;</td>
      <td align="left" class="EM_data_table_inputarea11"><input type="submit" name="Submit" value="Update" onClick="return checkblank();">      </td>
    </tr>
  </table>
</form>